<?PHP
	require 'includes/master.inc.php';
	$auth->admin();
	$o = new Order($_GET['id']);
	if($o->id == "") redirect("orders.php");
	
	if(isset($_GET['email']) && $_GET['email'] == 'yes')
	{
		if($o->emailLicense())
			redirect("order.php?id=" . $_GET['id'] . "&email=sent");
		else
			$msg = "<p class='warn'>Email was not sent!</p>";
	}
	elseif(isset($_GET['email']) && $_GET['email'] == 'sent')
	{
		$msg = "<p class='alert'>Email sent!</p>";	
	}
	
	if(isset($_POST['btndelete']))
	{
		$o->deleted = 1;
		$o->update();
		redirect("orders.php");
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>View Order | Appcaster</title>
	<?PHP include 'inc/meta.inc.php'; ?>
</head>

<body id="home">
	<?PHP include 'inc/head.inc.php'; ?>
	<div id="nav">
		<ul>
			<li><a href='<?PHP WEBROOT();?>index.php'>Applications</a></li>
			<li class='selected'><a href='<?PHP WEBROOT();?>orders.php'>Orders</a></li>
			<li><a href='<?PHP WEBROOT();?>feedback.php'>Feedback (<?PHP echo Feedback::newCountTotal();?>)</a></li>
			<li><a href='<?PHP WEBROOT();?>stats.php'>Stats</a></li>
			<li><a href='<?PHP WEBROOT();?>options.php'>Options</a></li>
		</ul>
	</div>

	<div id="menutabs">
		<ul id="tabnav">
			<li><a href='<?PHP WEBROOT();?>orders.php'>All Orders</a></li>
			<li class='selected'><a href='<?PHP WEBROOT();?>order.php?id=<?PHP echo $o->id;?>'>Order #<?PHP echo $o->id;?></a></li>
			<li><a href='<?PHP WEBROOT();?>license.php?id=<?PHP echo $o->id;?>'>Download License</a></li>
			<li><a href='<?PHP WEBROOT();?>order.php?id=<?PHP echo $o->id;?>&amp;email=yes'>Email License</a></li>
		</ul>
	</div>

	<div id="contain">
		<?PHP if(isset($msg)) echo $msg; ?>
		<table>
			<?PHP foreach($o->keys() as $k) : ?>
			<tr>
				<th style="text-align:right;"><?PHP echo $k; ?></th>
				<td><?PHP echo $o->$k; ?></td>
			</tr>
			<?PHP endforeach; ?>
		</table>
		<form action="" method="post">
			<input type="submit" name="btndelete" value="Delete Order" id="btndelete"/></form>
		</form>
	</div>
</body>
</html>